---
- name: ensure packages required for buildslave are installed (dnf)
  dnf: name={{ item }} state=present enablerepo={{ extra_enablerepos }}
  with_items:
    - buildbot-slave
    - git
    - rpmlint
    - koji
    - bodhi-client
    - python-virtualenv
    - gcc
    - libcurl-devel
    - rpm-build
    - pylint
    - python-pep8
    - moreutils
    - policycoreutils-python-utils
  when: ansible_distribution_major_version|int > 21 and ansible_cmdline.ostree is not defined

- name: ensure packages required for CI buildslave are installed (dnf)
  dnf: name={{ item }} state=present enablerepo={{ extra_enablerepos }}
  with_items:
    - testcloud
    - mash
    - mock
    - koji
    - python-fedora
    - python-doit
    - python2-rpmfluff
  when: (deployment_type == 'qa-stg') and (ansible_distribution_major_version|int > 21) and (ansible_cmdline.ostree is not defined)

- name: set the selinux fcontext type for the buildmaster_home to var_lib_t
  command: semanage fcontext -a -t var_lib_t "{{ slave_dir }}(/.*)?"
  when: deployment_type in ['qa-stg']

- name: add the buildslave user for taskotron
  user: name=buildslave
  when: deployment_type in ['local']

- name: add the buildslave user for ci
  user: name=buildslave groups=mock
  when: deployment_type in ['qa-stg']

- name: ensure needed groups exist
  group: name={{ item }}
  when: deployment_type in ['dev', 'stg', 'prod']
  with_items:
    - testcloud
    - taskotron

- name: ensure needed groups exist
  group: name={{ slaves_group }}
  when: slaves_group is defined and (deployment_type in ['dev', 'stg', 'prod'])

- name: add buildslave users
  user: name={{ item.user }} group={{ slaves_group }} groups=testcloud,taskotron home={{ item.home }}
  with_items: "{{ slaves }}"
  when: slaves is defined and (deployment_type in ['dev', 'stg', 'prod'])

- name: set the selinux fcontext type for the buildslave dir to var_lib_t
  command: semanage fcontext -a -t var_lib_t "{{ item.dir }}"
  with_items: "{{ slaves }}"
  when: slaves is defined and deployment_type in ['qa-prod', 'qa-stg']

- name: make sure the selinux fcontext is restored
  command: restorecon -R "{{ item.dir }}"
  with_items: "{{ slaves }}"
  when: slaves is defined and deployment_type in ['dev', 'stg', 'prod', 'qa-prod', 'qa-stg']

- name: disable ansible host key checking
  lineinfile:
    dest: /etc/ansible/ansible.cfg
    regexp: '^#host_key_checking = False$'
    line: 'host_key_checking = False'
  when: deployment_type in ['dev']
